// FA_L_BPA.cpp: implementation of the CFA_L_BPA class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "../../Include/Swi/FA_L_BPA.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CFA_L_BPA::CFA_L_BPA()
{
	m_chType = 'F';
	m_chSubType = 'J';
	m_chChangeCode = ' ';

	m_dRc = 0;
	m_dXc = 0;
	m_dTr = 0;
	m_dVIMax = 0;
	m_dVIMin = 0;
	m_dTb = 0;
	m_dTc = 0;
	m_dKa = 0;
	m_dTa = 0;
	m_dVRMax = 0;
	m_dVRMin = 0;
	m_dKe = 0;
	m_dTe = 0;

	m_strCardType[0] = 'F';
	m_strCardType[1] = '1';
}

CFA_L_BPA::CFA_L_BPA(CFA_L_BPA &falBPA):CUnit_BPA(falBPA)
{
	m_dRc = falBPA.m_dRc;
	m_dXc = falBPA.m_dXc;
	m_dTr = falBPA.m_dTr;
	m_dVIMax = falBPA.m_dVIMax;
	m_dVIMin = falBPA.m_dVIMin;
	m_dTb = falBPA.m_dTb;
	m_dTc = falBPA.m_dTc;
	m_dKa = falBPA.m_dKa;
	m_dTa = falBPA.m_dTa;
	m_dVRMax = falBPA.m_dVRMax;
	m_dVRMin = falBPA.m_dVRMin;
	m_dKe = falBPA.m_dKe;
	m_dTe = falBPA.m_dTe;
}

CFA_L_BPA::~CFA_L_BPA()
{

}

bool CFA_L_BPA::FillEx(char *buffer)
{
	bool bResult = CUnit_BPA::FillEx(buffer);

	if (!bResult)
	{
		printf("Error in (CFA_L_BPA: FillEx): no basic information!\n");
		return false;
	}

	if (strlen(buffer)<17)
	{
		printf("Error in (CFA_L_BPA: FillEx): FA_L has no parameter!\n");
		return false;
	}

	m_dRc = StrToDouble(&buffer[16],5,4);
	if(EndOfSec(&buffer[16],5))
		return true;

	m_dXc = StrToDouble(&buffer[21],5,4);
	if(EndOfSec(&buffer[21],5))
		return true;

	m_dTr = StrToDouble(&buffer[26],5,4);
	if(EndOfSec(&buffer[26],5))
		return true;

	m_dVIMax = StrToDouble(&buffer[31],5,3);
	if(EndOfSec(&buffer[31],5))
		return true;

	m_dVIMin = StrToDouble(&buffer[36],5,3);
	if(EndOfSec(&buffer[36],5))
		return true;
	
	m_dTb = StrToDouble(&buffer[41],5,3);
	if(EndOfSec(&buffer[41],5))
		return true;
	
	m_dTc = StrToDouble(&buffer[46],5,3);
	if(EndOfSec(&buffer[46],5))
		return true;
	
	m_dKa = StrToDouble(&buffer[51],5,2);
	if(EndOfSec(&buffer[51],5))
		return true;
	
	m_dTa = StrToDouble(&buffer[56],5,3);
	if(EndOfSec(&buffer[56],5))
		return true;
	
	m_dVRMax = StrToDouble(&buffer[61],5,3);
	if(EndOfSec(&buffer[61],5))
		return true;

	m_dVRMin = StrToDouble(&buffer[66],5,3);
	if(EndOfSec(&buffer[66],5))
		return true;

	m_dKe = StrToDouble(&buffer[71],5,3);
	if(EndOfSec(&buffer[71],5))
		return true;

	m_dTe = StrToDouble(&buffer[76],4,3);
	if(EndOfSec(&buffer[76],4))
		return true;

	return true;
}

bool CFA_L_BPA::UpdateEx(char *buffer)
{
	bool bResult = CUnit_BPA::UpdateEx(buffer);

	if (!bResult)
	{
		printf("Error in (CFA_L_BPA: UpdateEx): impossible!\n");
		return false;
	}

	DoubleToStr(m_dRc,&buffer[16],5,4);
	DoubleToStr(m_dXc,&buffer[21],5,4);
	DoubleToStr(m_dTr,&buffer[26],5,4);
	DoubleToStr(m_dVIMax,&buffer[31],5,3);
	DoubleToStr(m_dVIMin,&buffer[36],5,3);
	DoubleToStr(m_dTb,&buffer[41],5,3);
	DoubleToStr(m_dTc,&buffer[46],5,3);
	DoubleToStr(m_dKa,&buffer[51],5,2);
	DoubleToStr(m_dTa,&buffer[56],5,3);
	DoubleToStr(m_dVRMax,&buffer[61],5,3);
	DoubleToStr(m_dVRMin,&buffer[66],5,3);
	DoubleToStr(m_dKe,&buffer[71],5,3);
	DoubleToStr(m_dTe,&buffer[76],4,3);

	return true;
}